<template>
  <div ref="root" class="app-intro-small-list">
    <mt-loadmore
      :bottom-method="getdata"
      ref="loadmore"
    >
      <div>
        <app-intro-small-item
          v-for="introSmallItem in introSmallList"
          :key="introSmallItem.id"
          :introSmallItem="introSmallItem"
          :pshow="pshow"
        ></app-intro-small-item>
      </div>
    </mt-loadmore>
  </div>
</template>

<script>
import AppIntroSmallItem from "@com/common/AppIntroSmallItem";
// import scroll from "@util/scroll";
import { Loadmore } from "mint-ui";

export default {
  data() {
    return {
      introSmallList: []
    };
  },
  mounted() {
    // scroll({
    //   el: this.$refs.root,
    //   getdata: this.getdata.bind(this)
    // });
  },
  computed: {
    pshow() {
      return this.urltype === {} ? false : true;
    }
  },
  methods: {
    getdata() {
      this.$ajax({
        method: "get",
        url: this.urltype.url
      })
        .then(res => {
          this.introSmallList = this.introSmallList.concat(res[this.urltype.type]);
          this.allLoaded = true;// 若数据已全部获取完毕
          this.$refs.loadmore.onBottomLoaded();
        })
        .catch(err => {
          console.log(err);
        });
      // this.$ajax
      // .get(this.urltype.url)
      // .then(results => {
      //   if (results.status === 200) {
      //     console.log("获取数据成功...");
      //     this.introSmallList = this.introSmallList.concat(results.data[this.urltype.type]);
      //   } else {
      //     console.log("发生未知错误，获取数据失败...");
      //   }
      // })
      // .catch(err => {
      //   console.log(err);
      // });
    }
  },
  props: {
    urltype: {
      default: {}
    }
  },
  created() {
    //'/my/movieOnInfoList' this.introSmallList = results.data['movieList'];
    // "/my/comingList?ci=1&token=&limit=10" "coming"
    this.getdata();
  },
  components: {
    AppIntroSmallItem,
    [Loadmore.name]: Loadmore
  }
};
</script>

<style lang="scss">
.app-intro-small-list {
  padding: 0 0.4rem 0.32rem 0.4rem;
  background-color: #fff;
  height: 100%;
  overflow: scroll;

  div {
    height: auto;
  }
}
</style>
